Global Replace in a multi-language environment
The EMu Global Replace facility is used to perform changes over a number of records. It provides a mechanism for applying the same update to a selected set of records. The Global Replace facility works by applying a user supplied string or pattern against a particular field, and where matches occur the matching text is replaced with another user supplied value. The important point here is that the string or pattern entered by the user to match against is compared to the data for a given field as it is stored on the server, that is as it is specified in the Supported Registry entry: any string or pattern supplied for replacement must therefore be in this same order. In order to enforce this restriction, the following functionality applies to the Global Replace facility:
- The Global Replace facility is disabled unless All Languages is selected for the language Data setting: that is, the Replace command cannot be invoked when viewing data in a single language.
The reason for the restriction is that any string or pattern used to find text to replace is searched for in the complete field value, not just the current Data language. For example, to replace the word total with aggregate in an English / French EMu system, the Global Replace facility will locate all instances of total and replace them with aggregate regardless of where in the data the text appears. Hence, where total appears in the French text, it is replaced with the English word aggregate. This means that a user could change values in a language other than the one they are viewing currently. In order to avoid this issue, the Global Replace facility is not available when viewing a single language.
- The Global Replace facility is disabled when All Languages is selected for the Data language setting and where the Display Order language setting is not the same order as that defined by the Supported Registry entry (which is displayed in the System Order field on the Language tab of the Options box).
The reason for the restriction is that it may not be possible to translate strings or patterns entered with arbitrary display order settings to values suitable for replacing. For example, in an English / French system with a Display Order of French / English, the string / pattern total;:; cannot be converted to a single pattern for applying to the English / French data stored in EMu. The string / pattern means to look for the word total where it is the last French word (as it has a trailing language delimiter entered). One possible solution is to translate the string / pattern as French$ so that French is the last word in the data. However such a string / pattern would match the following data:
- French
- English;:;French
In other words English data may be modified where only French changes were intended. There are a number of other patterns that are also problematic as they cannot be converted to a pattern suitable for use with English / French data. In order to avoid the accidental updating of values not intended to be updated, the Global Replace facility is only enabled for users who are viewing All Languages and the language Display Order is the same as that defined by the Supported Registry entry.
These examples assume a dual language environment in which data is stored on the server as English and then French.
Note: See Global Replace for details about defining a substitution; see Wildcards in a Global Replace for a description of the wildcard symbols used in these examples.
1.
|
Objective |
Search the Series Title: (Title Details) field for the first occurrence of the word total and replace it with the word amount. |
Original data |
|
|
Substitution |
|
|
Result |
|
|
Description |
Selecting First occurrence only tells EMu to search for the first occurrence of the word total and replace it with the word amount and then stop. |
|
2.
|
Objective |
This example demonstrates "greedy" patterns in operation. A "greedy" pattern is one which matches the longest string possible. (.*) is an example of a "greedy" pattern, although more generally, use of the * wildcard will initiate a "greedy" pattern match. When the Text to find includes a "greedy" pattern, pattern matching in the target field will find the longest matching sequence. Here we search the Series Title: (Title Details) field for the French word total (that is, total appears after the language delimiter) and replace it with montant. |
Original data |
|
|
Substitution |
|
|
Result |
|
|
Description |
Text to find
Entering the text to find (total) and expressions between ^ (which indicates the beginning of the field) and $ (which marks the end of the field) indicates that we're looking for (and replacing) the entire contents of the field. There are two expressions in this example, marked by the brackets:
Replace with \1montant\2 In this usage, the \ does not perform an escape function (as in \?, which means treat the ? as a question mark, not as a character with a special function). \1 refers to the first expression in the Text to find field: (.*;:;.*) \2 refers to the second expression in the Text to find field: (.*) In this case EMu is required to locate and replace: ^(.*;:;.*)total(.*)$ with: (Expression 1) montant (Expression 2) In other words: (What is the total;:;Quel est le) montant( ) |
|
3.
|
Objective |
Search the Series Title: (Title Details) field for the French word est and replace it with était. |
Original data |
|
|
Substitution |
|
|
Result |
|
|
Description |
Text to find ^(.*;:;.*)est The first thing to notice is that we are not replacing the entire content in the field as our Text to find does not sit between ^ and $. There is only one expression and it affects data from the word to be replaced (est) to the start of the field (again this involves a "greedy" pattern that matches the longest possible sequence). Our Text to find tells EMu to match everything from the last occurrence of est to the beginning of the field. Breaking this down further:
Replace with \1était \1 refers to the first expression in the Text to find field: (.*;:;.*) In this case EMu is required to locate and replace: ^(.*;:;.*)est with: (Expression1) était Anything else in the field after est is left alone. In other words: (What is the total;:;Quel) était le total |
|
4.
|
Objective |
This example demonstrates "greedy" patterns in operation again in a more complex setting. |
Original data |
|
|
Substitution |
|
|
Result |
|
|
Description |
If we weren't aware that use of the "greedy" pattern (.*) processes a match from the end of the field forwards, we might expect that this substitution would replace the second example, giving us: Language example One;:;Language EXAMPLE Two;:;Language example Three Instead, the following occurs: Text to find Starting from the end of the field (.*), which is Expression 2, matches everything up to example, i.e.: Three As a "greedy" pattern (.*) matches the longest string possible, which in this case is everything from the end of the field up to the last occurrence of example, which is the text to be replaced with EXAMPLE. ^(.*;:;.*), which is Expression 1, now matches everything from this point to the beginning of the field, i.e.: Language example One;:;Language example Two;:;Language Breaking this down further:
Replace with \1EXAMPLE\2 \1 is the first expression, which equates to: Language example One;:;Language example Two;:;Language \2 is the second expression, which equates to: Three Which gives us: Language example One;:;Language example Two;:;Language EXAMPLE three |